<?php

namespace App\Observers;

use App\Models\RealEstates;
use App\server\RedisServer;
use App\server\EsServer;
class RealEstatesObserver
{
    /**
     * Handle the RealEstates "created" event.
     *
     * @param  \App\Models\RealEstates  $realEstates
     * @return void
     */
    public function created(RealEstates $realEstates)
    {
        //
        $redis=RedisServer::createRedisObject();
        $redis->select(9);
        $realeEstatedata=$realEstates->toArray();
        (new EsServer())->EsAdd('reale_estate_index',$realeEstatedata);
        $redis->hSetone($realeEstatedata);
    }

    /**
     * Handle the RealEstates "updated" event.
     *
     * @param  \App\Models\RealEstates  $realEstates
     * @return void
     */
    public function updated(RealEstates $realEstates)
    {
        //
        $data=$realEstates->toArray();
        (new EsServer())->EsAdd('reale_estate_index',$data);
        $redis=RedisServer::createRedisObject();
        $redis->select(9);
        foreach ($data as $key => $value){
            $redis->hset($data['id'],$key,$value);
        }
    }

    /**
     * Handle the RealEstates "deleted" event.
     *
     * @param  \App\Models\RealEstates  $realEstates
     * @return void
     */
    public function deleted(RealEstates $realEstates)
    {
        //
    }

    /**
     * Handle the RealEstates "restored" event.
     *
     * @param  \App\Models\RealEstates  $realEstates
     * @return void
     */
    public function restored(RealEstates $realEstates)
    {
        //
    }

    /**
     * Handle the RealEstates "force deleted" event.
     *
     * @param  \App\Models\RealEstates  $realEstates
     * @return void
     */
    public function forceDeleted(RealEstates $realEstates)
    {
        //
    }
}
